home *** CD-ROM | disk | FTP | other *** search
- Path: pwolf-mac.qualcomm.com!user
- From: pwolf@qualcomm.com (Paul I. Wolf )
- Newsgroups: comp.lang.c
- Subject: Re: warning: possibly incorrect assignment
- Date: 9 Jan 1996 17:20:39 GMT
- Organization: Qualcomm, Inc.
- Message-ID: <pwolf-0901960920380001@pwolf-mac.qualcomm.com>
- References: <Pine.OSF.3.91.960109091920.6447A-100000@io.UWinnipeg.ca>
- NNTP-Posting-Host: pwolf-mac.qualcomm.com
-
- Your compiler is conservatively trying to warn you that you may be
- assigning instead of comparing FILE* objects with "==".
-
- You may be able to use an extra pair of parentheses to suppress the warning
- "while((fp=fopen(file_name,"r")))", but it depends on your compiler.
- Otherwise, you must separate the assignment and comparison statements to
- prevent being warned
-
- In article <Pine.OSF.3.91.960109091920.6447A-100000@io.UWinnipeg.ca>, Bill
- Simpson <wsimpson@uwinnipeg.ca> wrote:
-
- > I get the above warning when I compile code using the following
- > function. It flags the **** line.
- >
- > void save_data(unsigned long int time[],int n)
- > {
- > char file_name[30];
- > double t;
- > int i;
- > FILE * fp;
- >
- > printf("Enter file name: ");
- > scanf("%s", file_name);
- >
- > **** while(fp=fopen(file_name,"r"))
- > {
- > printf("this file already exists--use another name\n");
- > fclose(fp);
- > printf("Enter filename:\n");
- > scanf("%s", file_name);
- > }
- >
- > fp=fopen(file_name,"w");
- > for (i=0;i<n;i++)
- > {
- > t=(double)time[i]/1000000; /*convert from microsec to sec*/
- > fprintf(fp,"%.6f\n",t);
- > }
- > fclose(fp);
- >
- > return;
- > }
- >
- > How can I write this code so the compiler does not issue this warning?
- > Please don't suggest I just tell the compiler to shut up. In general
- > the warnings are useful. I do not want to just ignore the warning either.
- > I have the FAQ and haven't seen this discussed.
- >
- > (Any other improvements to above code segment welcomed)
- >
- > Thanks very much for any help.
- >
- > Bill Simpson
-